<template>
	<view class="bg-white flex flex-direction" style="height: 100vh;">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">
				<text>讲书</text>
			</block>
		</cu-custom>
		<!-- 专栏组件 -->
		<column :columnType="4" class="flex-sub flex  flex-direction" :tablist="tablist" ref="column" @change="handleChange">
			<!-- 轮播展示 -->
			<swiper class="margin flex-sub" @change="onSwiperchange" :current="current">
				<swiper-item v-for="(item,num) in tablist" :key="num">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="loadMoreData">
						<view v-for="(book,index) in booklist" :key="index" class="margin-top" @click="goToBookDetail(book.id)">
							<!-- 展示列表 -->
							<book-cell :book="book"></book-cell>
						</view>
						<load-more :status="item.loadMoreStatus"></load-more>
					</scroll-view>
				</swiper-item>
			</swiper>
		</column>
	</view>
</template>

<script>
	import cuCustom from '../../plugin/colorui/components/cu-custom.vue'
	import column from '../../components/column/column.vue'
	import loadMore from '../../components/mine/loadMore.vue';
	import bookCell from '../../components/column/bookCell.vue'
	export default {
		components: {
			column,
			bookCell,
			loadMore,
			cuCustom
		},
		data() {
			return {
				current: 0,
				page: 1,
				tablist: [],
				booklist: []
			}
		},
		onLoad() {
			this.$http.get('/edu/onesubject/getAllOneSubject').then(res =>{
				this.tablist=res.data.result
				this.tablist.forEach(item =>{
					item.loadMoreStatus=0
					item.id="a"+item.id
				})
				// console.log(this.tablist)
			})
			this.$http.get('/edu/book/getAllBook').then(res => {
				this.booklist = res.data;
			})
		},
		methods: {
			loadMoreData() {
				this.tablist[this.current].loadMoreStatus = 1;
				// 更改加载页数
				this.page++;

				if (this.booklist.length < 10) {
					this.booklist = this.booklist.concat(this.booklist);
					this.tablist[this.current].loadMoreStatus = 0;
				} else {
					this.tablist[this.current].loadMoreStatus = 2;
					this.$forceUpdate()
				}
			},
			onSwiperchange(e) {
				this.$refs.column.switchtab(e.detail.current)
				this.current = e.detail.current
				this.tablist[this.current].loadMoreStatus = 0;
			},
			handleChange(index) {
				this.current = index
				this.tablist[this.current].loadMoreStatus = 0;
			},
			goToBookDetail(id) {
				this.$Router.push({name:'bookDetail',params:{id:id}})
			}
		}
	}
</script>

<style>
</style>
